<?php
namespace app\home\model;
use think\Model;


class Article extends Model
{
    protected $pk = 'id';
    protected $schema = [
        'id'        => 'int',
        'title'     => 'string',
        'summary'   => 'string',
        'addtime'   => 'datetime',
        'content'   => 'string',
        'image'     => 'string',
        'source'    => 'string',
        'updatatime'=> 'string',
        'hot_order' => 'int',
        'hash_str'  => 'string',
        'keywords'  =>  'string',
    ];
    public function getAddtimeAttr($value)
    {
        return get_date($value);
    }
    public function getUpdatatimeAttr($value)
    {
        return get_date($value);
    }
    public function getDescAttr($value, $data){
        $desc = $data['title']."【真木网】";
        return $desc ;
    }
    public function getKwAttr($value, $data){
        return Seo::getKeywords();
    }
    public static function getByOrder($order="date", $limit=5)
    {
        $order_option = [
            'date'              =>  'addtime',
            'date_desc'         =>  'addtime desc',    
            'hot'               =>  'hot_order',
            'hot_order_desc'    =>  'hot_order desc'
        ];
        return self::field(['image', 'title', 'summary', 'updatatime', 'hash_str'])
                    ->order($order_option[$order])
                    ->where("title is not null or title != ''")
                    ->limit($limit)
                    ->select();
    }
}
